package cn.jjxx.core.swagger;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;

import cn.jjxx.modules.sys.entity.User;

import com.fasterxml.classmate.TypeResolver;
 
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.AlternateTypeRule;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
 
@Configuration //声明该类为配置类
@EnableSwagger2 //声明启动Swagger2
@EnableWebMvc //声明启动mvc
public class SwaggerConfig{
	
	//方法一：添加过滤规则，移除嵌套对象（使用对象会造成递归循环，无法退出）
	TypeResolver typResolver = new TypeResolver();
	AlternateTypeRule userRule = new AlternateTypeRule(typResolver.resolve(User.class), typResolver.resolve(Object.class));
	//方法二：
	
    @Bean
    public Docket customDocket() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .alternateTypeRules(userRule)
                .select()
                .apis(RequestHandlerSelectors.basePackage("cn.jjxx.modules.iface"))//扫描的包路径
                //.apis(RequestHandlerSelectors.any())//对所有Api监控
                .paths(PathSelectors.any())//对所有路径监控
                //.paths(PathSelectors.ant("/iface/activiti/**"))
                //.paths(PathSelectors.ant("/iface/mobile/**"))
                .build();
    }
 
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("基础开发框架 API接口")//文档说明
                .version("1.0.0")//文档版本说明
                .build();
    }

}
